package main

import "fmt"

// main
//
//	@Description: 桥接模式：将抽象部分与实现部分分离，使得他们可以独立变化。提高代码的可扩展性。
func main() {
	mac := &MacComputer{}
	mac.SetPrinter(&EpsonPrinter{})
	mac.Print("hello world")

	fmt.Println()
	windows := &WindowsComputer{}
	windows.SetPrinter(&HpPrinter{})
	windows.Print("hello world")

}

// Printer 打印机
type Printer interface {
	Print(content string) // 打印文件
}

type HpPrinter struct {
}

func (h *HpPrinter) Print(content string) {
	println("使用惠普打印：" + content)
}

type EpsonPrinter struct {
}

func (x *EpsonPrinter) Print(content string) {
	println("使用爱普生打印：" + content)
}

// Computer 电脑
type Computer interface {
	Print(content string) // 打印
	SetPrinter(Printer)   // 设置打印机
}

type MacComputer struct {
	printer Printer
}

func (m *MacComputer) Print(content string) {
	fmt.Println("mac电脑，")
	m.printer.Print(content)
}
func (m *MacComputer) SetPrinter(printer Printer) {
	m.printer = printer
}

type WindowsComputer struct {
	printer Printer
}

func (w *WindowsComputer) Print(content string) {
	fmt.Println("win电脑，")
	w.printer.Print(content)
}
func (w *WindowsComputer) SetPrinter(printer Printer) {
	w.printer = printer
}
